import * as camelcase from 'camelcase'

/** 延迟多少时间
 * @param {number} millisecond
 */
function delay(millisecond = 800) {
    return new Promise(resolve => setTimeout(() => resolve(), millisecond));
}

function toCamel(o: Object | Array<any>) {
    var newO,
        origKey,
        newKey,
        value
    if (o instanceof Array) {
        newO = []
        for (value of o) {
            if (typeof value === "object") {
                value = toCamel(value)
            }
            newO.push(value)
        }
    } else {
        newO = {}
        for (origKey in o) {
            if (o.hasOwnProperty(origKey)) {
                newKey = camelcase(origKey)
                value = o[origKey]
                if (value instanceof Array || (value !== null && value.constructor === Object)) {
                    value = toCamel(value)
                }
                newO[newKey] = value
            }
        }
    }
    return newO
}

export { toCamel, delay }
